import { createRouter, createWebHistory } from 'vue-router';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'indexComponent',
      component: () => import('@/views/index.vue'),
      redirect: '/tableComponent',
      children: [
        {
          path: 'tableComponent',
          name: 'tableComponent',
          meta: { title: '表格展示' },
          component: () => import('@/views/table/index.vue')
        },
        {
          path: 'echartsComponent',
          name: 'echartsComponent',
          meta: { title: '图形展示' },
          component: () => import('@/views/eCharts/index.vue')
        },
        {
          path: 'aiComponent',
          name: 'aiComponent',
          meta: { title: '智能分析' },
          component: () => import('@/views/ai/index.vue')
        }
      ]
    }
  ]
});

router.beforeEach(async (to, _from) => {
  if (typeof to.meta.header === 'string') {
    document.title = to.meta.header;
  } else if (typeof to.meta.title === 'string') {
    document.title = to.meta.title || '上核检测';
  }
});

export default router;
